package org.bf.sms.persistent;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Reader;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.bf.sms.config.SysConfig;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

/**
 * 获取数据源
 * 
 * @author LiuChang
 * @version 1.0 2010-12-07
 * @since 1.0
 */
@Deprecated
public class DaoConfig
{

	/** IBatis配置信息 */
	private static Reader reader;

	/** 数据库配置信息 */
	private static Properties props;

	/** log4j */
	private static final Logger LOGGER = Logger.getLogger(DaoConfig.class);

	static {

		// String resource = "com/ricky/jdforum/persistence/dao.xml";
		try {
			DaoConfig.reader = Resources
					.getResourceAsReader(SysConfig.IBATIS_CONFIG_MYSQL);

			File file = new File(SysConfig.DB_PROPERTIES);
			Properties prop = new Properties();
			prop.load(new FileInputStream(file));
			// DaoConfig.props = prop;
			DaoConfig.props = prop;
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public static SqlMapClient getSqlMapClient()
	{
		return SqlMapClientBuilder.buildSqlMapClient(reader); //$NON-NLS-1$
	}

}
